package com.example.msg;

import cn.hutool.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> extends BaseResponse {

    private T data;


    /**
     * 默认的成功方法
     */
    public static Result success() {
        return new Result(HttpStatus.HTTP_OK, "执行成功！");
    }

    /**
     * 带有data的成功方法
     *
     * @param data data数据
     * @return
     */
    public static Result success(Object data) {

        return new Result<>().data(data);
    }


    /**
     * 带有消息的成功方法
     *
     * @param msg 消息
     */
    public static Result successWithTip(String msg) {
        return new Result(HttpStatus.HTTP_OK, msg);
    }


    /**
     * 带有 错误提示消息 的失败方法
     *
     * @param msg 错误提示
     */
    public static Result error(String msg) {
        return new Result(HttpStatus.HTTP_INTERNAL_ERROR, msg);
    }

    /**
     * 自定义错误码、提示信息的失败方法
     *
     * @param code 错误码
     * @param msg  提示消息
     */
    public static Result error(int code, String msg) {
        return new Result(code, msg);
    }

    private Result(int code, String msg) {
        super(code, msg);
    }

    private Result<T> data(T data){
        this.data=data;
        return this;
    }

   /*  private Result data(T data) {
        this.setData(data);
        return this;
    } */
}
